package com.rimi.bbs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rimi.bbs.bean.User;
import com.rimi.bbs.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

@Component
public class MyUserDetailsService implements UserDetailsService {

    @Autowired
    private UserMapper userMapper;


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        // TODO 根据用户名，查找到对应的密码，与权限
        User user = userMapper.selectOne(new QueryWrapper<User>().eq("user_email", username));
        /*if (user == null) {
            throw new UsernameNotFoundException("用户名或密码错误");
        } else if(!user.isAccountNonLocked()){
            //throw new LockedException("用户已被锁定");
        }*/
        // 封装用户信息，并返回。参数分别是：用户名，密码，用户权限
        return user;
    }

}
